package com.xiashitech.agent.instrumentation.biz.desensitization.httpurl.filter;

import com.xiashitech.agent.dto.UserRequest;
import io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.GlobalOpenTelemetry;

import javax.servlet.http.HttpServletResponse;

public class XSServletSingletons {
    private XSServletSingletons() {}
    private static final String INSTRUMENTATION_NAME = "com.xiashitech.biz.desensitization.httpurl.filter";
    private static final String SPAN_NAME = "xs.desensitization-filter-span";
    private static final Instrumenter<UserRequest, HttpServletResponse> INSTRUMENTER;

    public static Instrumenter<UserRequest, HttpServletResponse> instrumenter() {
        return INSTRUMENTER;
    }

    static {
        INSTRUMENTER =
                Instrumenter.<UserRequest, HttpServletResponse>builder(
                                GlobalOpenTelemetry.get(),
                                INSTRUMENTATION_NAME,
                                request -> SPAN_NAME
                        ).addAttributesExtractor(new XSServletAttributesExtractor())
                        .buildInstrumenter();
    }
}
